Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a need to use double quotes vs no quotes when appending an array in postgresql?

Consider a DB where there is a column tags which is a TEXT[]:

Using double quotes:

UPDATE my_table SET tags = tags || '{"na"}' WHERE name = 'Cat';

Using no quotes:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UPDATE my_table SET tags = tags || '{na}' WHERE name = 'Cat';

Both cases will update a row where name == Cat and append a string "na" to the list of tags. Is there a practical difference between these two methods?

>Solution :

No, there isn’t:

SELECT '{na}'::text[] = '{"na"}'::text[];

 ?column? 
══════════
 t
(1 row)

You need the double quotes only as an escape character if the array element contains a {, } or , character.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading