English 中文(简体)
动态查询后格
原标题:dynamic query postgres

我新来张贴gres 并跟随动态查询运行

EXECUTE  Select * from products ;

我得到以下回应。

ERROR: syntax error at or near " Select * from products " 
LINE 1: EXECUTE  Select * from products ;

我知道这是我缺少的基本东西

问题回答

有 < deco> EXECUTE 语句 < strong> plpgsql , 这将做你想做的事 - 执行 SQL 查询字符串 。 您标记了 < a href="/ questions/ ttract/ directive" 类 = “ post-tag” 标题 = “ 显示标有动态“ rel=“ tag” > 动力 , 所以这可能是您正在寻找的问题 。

只工作在 plpgsql 函数或 < a href=' http://www. postgresql.org/docs/put/interactive/sql-do.html" rel= "nofollow"\ code > DO (匿名代码区块) 。 < a href=> http://www.postgresql.org/docs/putive/interactive/plpgsql-statements.html#PLPLPGSQL-STATINGS-EXECUTING-DYN" rel="nofol" > 。

Note: The PL/pgSQL EXECUTE statement is not related to the EXECUTE SQL statement supported by the PostgreSQL server. The server s EXECUTE statement cannot be used directly within PL/pgSQL functions (and is not needed).

如果您想要按您的例子从动态 SELECT 查询返回值, 您需要创建函数 。 DO 语句总是返回 evue . 。 http://www. pagegresql. org/docs/ pext/interactive/ plpgsql- control- structs. html# PLPGSQL- StatAments- RETNING” rel=“ nofollow” > 有关从非常精细的手册中的函数返回值的 More 。

http://www.postagresql.org/docs/current/interactive/sql-execute.html" rel=“no follow” >fine 手册:

<强度 > 简要说明

EXECUTE name [ ( parameter [, ...] ) ]

<强 > 描述

EXECUTE 用于执行先前准备的声明。

所以 EXECUTE 不执行 SQL 的字符串, 它执行一份以名称标明的预写声明, 您需要使用 < a href=" http:// www. plasgresql. org/docs/ p流/ interactive/ sql- prepare. html", rel=“ nofollow” 单独编写声明 。

=> prepare stmt as select * from products;
=> execute stmt;
-- "select * from products" output goes here...




相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签