Sample Header Ad - 728x90

PostgreSQL - CAST vs :: operator on LATERAL table function

6 votes
2 answers
5128 views
While I can
SELECT
  elem, elem
FROM
  (
    VALUES ('1,2'::TEXT)
  ) AS q(arr),
  LATERAL CAST(String_To_Array(q.arr, ',') AS INT[]) AS elem
;
using an explicit call to CAST, I *can't*
SELECT
  elem, elem
FROM
  (
    VALUES ('1,2'::TEXT)
  ) AS q(arr),
  LATERAL String_To_Array(q.arr, ',')::INT[] AS elem
;
using the implicitly calling :: operator: > ERROR: syntax error at or near "::" One other location at which an explicit CAST is required:
CREATE INDEX ON ... ( CAST( AS ) );
` I doubt there is a syntactical reason, e.g. using extra enclosing parenthesis - which is incorrect here. Is the explicit function call simply needed at this point as part of the low level implementation? Or does it follow any language rules?
Asked by geozelot (183 rep)
Nov 26, 2020, 10:26 PM
Last activity: Nov 18, 2023, 12:34 PM