What does :: do in PostgreSQL? [duplicate]

北战南征 提交于 2019-11-28 16:48:10
PSR

A type cast specifies a conversion from one data type to another.

PostgreSQL accepts two equivalent syntaxes for type casts, the PostgreSQL-specific value::type and the SQL-standard CAST(value AS type).

In this specific case, '{apple,cherry apple, avocado}'::text[]; takes the string literal {apple,cherry apple, avocado} and tells PostgreSQL to interpret it as an array of text.

See the documentation on SQL expressions and arrays for details.

What @PSR and @Craig wrote.
Plus, there are two more syntax variants:

1. type value

This form only casts constants (string literals). Like in:

SELECT date '2013-03-21';

More in the manual in the chapter Constants of Other Types.

2. type(value)

That's the function-like syntax. Works only for types whose names are valid as function names. Like in:

SELECT date(date_as_text_col) FROM tbl;

More in the manual in the chapter Type Casts.

More comprehensive answer:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!