首页 \ 问答 \ PL / pgSQL执行与执行(PL/pgSQL perform vs execute)

PL / pgSQL执行与执行(PL/pgSQL perform vs execute)

在PL / pgSQL上执行和执行有什么区别?

从手册:

有时,对表达式或SELECT查询进行求值,但丢弃结果很有用,例如,在调用具有副作用但没有有用结果值的函数时。 要在PL / pgSQL中执行此操作,请使用PERFORM语句。

但是,当我尝试这样的事情时:

perform 'create table foo as (select 1)';

什么都没发生。 虽然这个查询应该有副作用(创建表),并且结果可以被丢弃。

我想我有一件事是正确的:为了运行功能我可以使用执行:

perform pg_temp.addInheritance(foo);

What are the difference between perform and execute on PL/pgSQL?

From the manual:

Sometimes it is useful to evaluate an expression or SELECT query but discard the result, for example when calling a function that has side-effects but no useful result value. To do this in PL/pgSQL, use the PERFORM statement.

But, when I'm trying something like:

perform 'create table foo as (select 1)';

Nothing happens. Although this query should have side effects (creating table), and the result can be discarded.

I think I get 1 thing right: in order to run functions I can use perform:

perform pg_temp.addInheritance(foo);

原文:https://stackoverflow.com/questions/42920998
更新时间:2022-12-01 20:12

最满意答案

在你的代码中你有这样一行:

import IHR_TestSuiteConfig.py

这是行不通的,因为你没有指定通过文件名称,而是通过模块名称导入的模块,例如:

import IHR_TestSuiteConfig

但是看看你的屏幕截图,你有一个更大的代码保存在Settings目录中的问题与你的Lib目录包含你正在导入的代码相同的级别。

您需要将所有代码都定位到一个级别,以便您可以执行以下操作:

from ..Settings import IHR_TestSuiteConfig

或者你需要操纵你的PYTHONPATH环境变量来将Settings直接放到sys.path (在VS Code中你可以创建一个.env文件来做到这一点,但是它不会'影响从终端运行Python,只有当VS Code运行例如Pylint)。


In your code you have the line:

import IHR_TestSuiteConfig.py

That won't work because you don't specify modules to import by file name but by module name, e.g.:

import IHR_TestSuiteConfig

But looking at your screenshot you have a bigger issue of the code being kept in a Settings directory at the same level as your Lib directory containing the code you are importing into.

You need to either anchor all of your code up a level so you can do:

from ..Settings import IHR_TestSuiteConfig

Or you need to manipulate your PYTHONPATH environment variable to put Settings directly on to sys.path (in VS Code you can create a .env file to do this, but it won't' affect running Python from the terminal, only when VS Code runs e.g. Pylint).

相关问答

更多
  • 您似乎可能无法理解“导入”的用法。 访问变量(或其他)有两种方法:1。 import getReady # you can getReady.salesPersonID 2。 from getReady import salesPersonID #you can salesPersonID 就我个人而言,这些代码并不是非常pythonic。 ^ _ ^ It seems that you may not understand the usage of "import". There are two ...
  • 插件系统可以像插件将自己或相关对象/方法添加到某个地方的全局列表一样简单。 另一方面,有一些类似zope.component架构的东西,你可以将应用程序变成组件,其中插件不仅可以将自己添加到列表中,而是替换部分应用程序。 zope.component 很酷 。 :-) 但是,是的,无论如何你需要某个地方来导入插件/组件。 在Python 3中,我将使用importlib.import_module() 。 importlib也适用于Python 2,并且包含在Python 2.7中,但是如果你不想要更多依赖 ...
  • 我认为它与生活在不是直接在我定义的PATH上的位置的qtconsole依赖关系有关,我相信我的模块搜索PATHS中存在一些冲突。 我发现最简单的解决方案是使用环境变量PYTHONPATH 。 从我原来的帖子开始已经有一段时间了,从那以后有几件事发生了变化,但我认为重要的因素是: - 小心在64位Windows上安装32位python。 - 使用PYTHONPATH包含重要的子目录,例如'/ install-dir / Lib'或其他任何子目录。 如果你的env变量仍然有问题,请使用绝对命令作为故障保护(将它 ...
  • 我会尝试回答你问题的第二部分。 from tkinter import *然后是Label() , Tk()这是一种不好的做法,因为它混合了命名空间,可能会混淆未来的代码读者。 例如,许多模块都有sqrt函数(标准库math , numpy , scipy )。 如果你对其中几个使用import all( * ),那么最后一个将获胜。 有时模块具有覆盖标准python函数的函数,并且读者无法知道此特定函数的来源。 即使您只在一个模块上使用import-all,读者也必须区分标准python函数和包函数,例如 ...
  • 在你的代码中你有这样一行: import IHR_TestSuiteConfig.py 这是行不通的,因为你没有指定通过文件名称,而是通过模块名称导入的模块,例如: import IHR_TestSuiteConfig 但是看看你的屏幕截图,你有一个更大的代码保存在Settings目录中的问题与你的Lib目录包含你正在导入的代码相同的级别。 您需要将所有代码都定位到一个级别,以便您可以执行以下操作: from ..Settings import IHR_TestSuiteConfig 或者你需要操纵你 ...
  • 这似乎是GCC 6.3.0错误的后果。 最低限度的复制: #include int main() { typeid(int).name(); } 这个程序在cygwin下的gcc 6.3.0下(在我的机器上无论如何)都会出现段错误。 This appears to be consequence of a GCC 6.3.0 bug. A minimal reproduction: #include int main() { typeid(in ...
  • 所以终于明白了 您需要在测试期间创建虚拟环境,这是最终的命令 #!/bin/bash export WORKSPACE=`pwd` # Create/Activate virtualenv virtualenv testenv -p /usr/bin/python3 source testenv/bin/activate # Install requirements pip install -r requirements/test.txt # Run them tests python my ...
  • 将所有要保存的参数附加到对象然后使用pickle模块来处理序列化会不会更容易? >>> class Save(object): pass ... >>> s = Save() >>> s.foo = 'foo' >>> s.bar = 42 >>> import pickle >>> fp = open('save.pickle', 'wb') >>> pickle.dump(s, fp) >>> fp.close() >>> >>> fp2 = open('save.pickle', 'rb') >>> ...
  • 将__init__.py文件放在stats文件夹中(正如其他人所说),并将其放入其中: from .cars import neon, mustang from .trucks import truck_a, truck_b 不是那么整洁,但更容易使用*通配符: from .cars import * from .trucks import * 这样, __init__.py脚本会为您执行一些导入,进入自己的命名空间。 现在,您可以在导入stats后直接使用neon / mustang模块中的函数/类: ...
  • 你应该在出错时抛出异常。 这样就可以像使用with关键字一样实现正确的对象破坏。 如果你提出异常,你不关心result因为你的功能不会“以正常方式”返回。 因此,函数调用左侧的指令也不会执行try块的其余部分。 You should throw an exception upon error. This enable lot of advance construction like proper object destruction like with the with keyword for instan ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)