zoukankan      html  css  js  c++  java
  • postgresql shell脚本传递参数并执行sql脚本并

    参考:

    https://stackoverflow.com/questions/7389416/postgresql-how-to-pass-parameters-from-command-line

    https://blog.csdn.net/dazuiba008/article/details/79268537  (推荐)

    ######################################数据库表结构######################################
    # name character

    #######################################命令行执行#######################################
    # shell命令连接postgres数据库
    psql 数据库名 用户名 -v name="Hello World"
    # 接收变量 注意: 如果参数是字符串类型那么接收的时候必须是 :'变量名' 这种形式;如果是数字类则为 :变量名
    select * from tableName where name = :'name';

    #################################命令行执行sql脚本(查询操作)###########################
    # shell命令连接postgres数据库
    psql 数据库名 用户名 -v name="Hello World" -f test.sql
    # test.sql 注意: 如果参数是字符串类型那么接收的时候必须是 :'变量名' 这种形式;如果是数字类则为 :变量名
    select * from tableName where name = :'name';

    #################################命令行执行sql脚本(插入操作)###########################
    # shell命令连接postgres数据库
    psql 数据库名 用户名 -v name="Hello World" -f test.sql
    # test.sql 注意:1.tableName后面必须跟上全列名 2.如果参数是字符串类型那么接收的时候必须是 :'变量名' 这种形式;如果是数字类则为 :变量名
    insert into tableName(name) where name = :'name';

    字符串操作

          参考:https://www.postgresql.org/docs/9.1/static/functions-string.html  

  • 相关阅读:
    汉诺塔问题
    两个有序链表序列的合并
    数列求和
    求集合数据的均方差
    [NOIP2014] 提高组 洛谷P1328 生活大爆炸版石头剪刀布
    [NOIP2014] 普及组
    洛谷P1726 上白泽慧音
    洛谷P1808 单词分类
    洛谷P1889 士兵站队
    洛谷P1288 取数游戏II
  • 原文地址:https://www.cnblogs.com/lvlin241/p/9280395.html
Copyright © 2011-2022 走看看