Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the USER keyword in PostgreSQL

Shulou Source: shulou.com Published: 2022-06-02 06:19:28 10月16日 Update

This article will explain in detail how to use the USER keyword in PostgreSQL, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Someone switched from MySQL to PG, and the structure of the user table is about this.

CREATE TABLE "user" (userid int,username text,...)

It is not possible without double quotation marks, USER is a reserved keyword.

Guess that some kind of GUI tool is used to build the table, which automatically puts double quotation marks on the table name, so there is no problem in creating it.

Run SQL:SELECT * FROM user through JDBC

Then rs.getString (2) tries to fetch the user name and is told to exceed the range of columns. The problem was not solved until we noticed that the table was called user.

Let's give it a try. Both ways are fine.

Flying=# select user; user- quanzl (1 row) flying=# select * from user; user- quanzl (1 row)

What grammatical element is user? It can appear both in the target list as a pseudo column and in the FROM list as a pseudo table that returns the result set (the word I invented myself). The former is easy to understand. Let's take a look at the latter.

From_clause: FROM from_list {$$= $2;} | / * EMPTY*/ {$$= NIL;}; from_list: table_ref {$$= list_make1 ($1);} | from_list', 'table_ref {$$= lappend ($1, $3);}

This is the syntax definition of the FROM clause, which is part of the definition of table_ref

| | func_table func_alias_clause {RangeFunction * n = (RangeFunction *) $1; n-> alias = linitial ($2); n-> coldeflist = lsecond ($2); $$= (Node *) n;} |

Func_table definition

Func_table: func_expr_windowless opt_ordinality

Func_expr_windowless definition

Func_expr_windowless: func_application {$$= $1;} | func_expr_common_subexpr {$$= $1;}

In func_expr_common_subexpr grammatical structure

| | USER {$$= makeSQLValueFunction (SVFOP_USER,-1, @ 1);} |

That's where FROM user came from.

On how to use the USER keyword in PostgreSQL to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Keywords keywords grammar content quotation marks articles more users knowledge articles structures questions yes elements clauses that is tools methods user names results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple vpn OPPO Reno Redmi