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
最满意答案
在你的代码中你有这样一行:
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 yourLib
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 putSettings
directly on tosys.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 ...
-
如何根据Python 3中的变量值导入模块?(How to import a module based on the value of a variable in Python 3?)[2022-03-09]
插件系统可以像插件将自己或相关对象/方法添加到某个地方的全局列表一样简单。 另一方面,有一些类似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模块中的函数/类: ...
-
Python 3:共享包:从导入的函数返回结果和错误(Python 3: Shared packages: Returning results and errors from imported functions)[2023-05-03]
你应该在出错时抛出异常。 这样就可以像使用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 ...