سؤال

What does it mean when a SQL statement in postgres is written like the following?

SELECT 
    name||' ::: '||id AS title
FROM 
    my_table;

It's almost impossible to search in Google! What do the pipes and enclosed quoted colons do?

هل كانت مفيدة؟

المحلول

From the fine manual:

Function: string || string
Return Type: text
Description: String concatenation
Example: 'Post' || 'greSQL'
Result: PostgreSQL

So a || b is string concatenation. This is standard SQL, some non-standard databases use concat(a, b) or a + b.

Single quotes are used in (standard) SQL for string literals so ' ::: ' is just a string.

That means that the whole thing:

name||' ::: '||id

is just the name and id pasted together with ' ::: ' between them. That SQL would probably be easier to read if the author added a little bit of whitespace:

name || ' ::: ' || id

BTW, you'll have better luck using SymbolHound to search for such things:

http://symbolhound.com/?q=postgresql+%7C%7C

نصائح أخرى

This simply do a select statement for two fields of the table by concatenating them with a text ' ::: ' at the middle.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top