0

I want to get type of column from postgresql trigger function.

This query returns type of items:

Select pg_typeof(shape) from sde.my_points;

And this query returns type of geometry:

Select  GeometryType(shape) from sde.my_points;

I want to use this parts in postgresql trigger function:

 CREATE FUNCTION point_xy() RETURNS trigger AS $point_xy$
        BEGIN
                IF (SELECT pg_typeof(NEW.shape)) = ('geometry')
                   AND  GeometryType(NEW.shape) = ('POINT')
                THEN
                        NEW.x = st_x(NEW.shape);
                        NEW.y = st_y(NEW.shape);
                END IF;
            END IF;

            RETURN NEW;
        END
        $point_xy$ LANGUAGE plpgsql;

This function gives error, in this line (SELECT pg_typeof(NEW.shape)).

ERROR: invalid input syntax for type oid: "geometry"

QUERY: SELECT (SELECT pg_typeof(NEW.shape)) = ('geometry') AND GeometryType(NEW.shape) = ('POINT')

CONTEXT: PL/pgSQL function point_xy() line 7

How can I use in function?

2
  • What's the error? Commented Jan 17, 2018 at 9:21
  • updated error code. Commented Jan 17, 2018 at 9:25

1 Answer 1

2

pg_typeof() returns a regtype value, but the associated = operator can compare any kind of OIDs, so the value on the other side could be a type, a table, a function... The string 'geometry' can't be automatically interpreted as a type name, so you'll need to cast it yourself. Try:

pg_typeof(NEW.shape) = 'geometry'::regtype
Sign up to request clarification or add additional context in comments.

1 Comment

By the way, no need for the SELECT, just IF pg_typeof(NEW.shape)='geometry'::regtype AND GeometryType(NEW.shape)='POINT' THEN ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.