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  

  • 相关阅读:
    LeetCode-Letter Combinations of a Phone Number
    LeetCode-Sort Colors
    C++Memset误区
    LeetCode-Valid Palindrome
    LeetCode-Longest Consecutive Sequence
    C++豆知识索引
    C++ 哈希表
    LeetCode-Sum Root to Leaf Numbers
    LeetCode-Word LadderII
    LeetCode-Word Ladder
  • 原文地址:https://www.cnblogs.com/lvlin241/p/9280395.html
Copyright © 2011-2022 走看看