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  

  • 相关阅读:
    时间操作
    2021.10.9数据结构实验课作业
    2021.9.28数据结构实验课作业
    2021.9.15数据结构实验课作业
    2021.9.7数据结构实验课作业
    苹果ios开发,CocoaPods安装方法-2021/9/11
    写组件库文档常用的技术
    document.execCommand 的用法
    手写JSON.stringify
    Object常用方法
  • 原文地址:https://www.cnblogs.com/lvlin241/p/9280395.html
Copyright © 2011-2022 走看看