Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use "name" as a column name in PostgreSQL?

Can we use "name" as a column name in PostgreSQL?

I have tried it out and the table gets created successfully. Will it get any errors when I will be performing any operation on table or table data?

Is name the reserved keyword?

UPDATE: Tried this

select * from pg_get_keywords()

and found that "name" is the unreserved. Still want to confirm if i can use that name?

like image 794
VBMali Avatar asked Oct 20 '25 13:10

VBMali


1 Answers

https://www.postgresql.org/docs/current/static/datatype-character.html#DATATYPE-CHARACTER-SPECIAL-TABLE

"name" is internal type for object names

So yes - you can:

t=# create table "b@dPract!c3" ("name" text, "date" timestamptz);
CREATE TABLE
t=# insert into "b@dPract!c3" values('wrong',now());
INSERT 0 1
t=# select * from "b@dPract!c3";
 name  |             date
-------+-------------------------------
 wrong | 2018-05-09 08:38:53.612212+01
(1 row)

should you do it? Surely not! naming columns with data type names is easy, but really bad practice

like image 95
Vao Tsun Avatar answered Oct 22 '25 04:10

Vao Tsun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!