Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the USER keyword in PostgreSQL

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report