美文网首页
postgreSQL 常用sql

postgreSQL 常用sql

作者: 米诺zuo | 来源:发表于2020-12-10 22:25 被阅读0次

    更新

    update texl.book
    set "desc" = 'Engines will be built to the SM specifications, which ensures TOW entitlement?'
    where "id" = 10

    select

    select r.desc,r.id from texl.recipe_book

    add or update

    INSERT INTO {schema~}.sv_recipe ("comment", "sid","rid") VALUES (1, 2,3)
    ON CONFLICT ("sid","rid") DO UPDATE SET "comment" = $1;

    查找列名

    SELECT COLUMN_NAME
    from
    information_schema.columns
    where table_schema='geagp_sfdc' and table_name= 'case'

    创建表 UNIQUE创建唯一约束关系

    CREATE TABLE IF NOT EXISTS ${schema~}.email
    (
    esn character varying(20) NOT NULL,
    ft_number character varying(10) NOT NULL,
    ft_version character varying(5) NOT NULL,
    recipient json,
    UNIQUE(esn,ft_number,ft_version)
    )

    列名改为驼峰命名

    select esn, start_date as "startDate", end_date as "endDate",
    flight, flightday as "flightDay", taxi, hstaxi as "hsTaxi"
    from ${schema~}.plan

    模糊查询

    SELECT ftsi_number, ftsi_title, version, issue_date, compliance_statement
    FROM {schema~}.ftsi_rule_view where impact_ips like '%'||1||'%'

    创建主键

    CONSTRAINT config_pkey PRIMARY KEY (key)

    创建约束

    CONSTRAINT email_recipient_esn_ft_number_ft_version_key UNIQUE (esn, ft_number, ft_version)

    创建枚举值

    COMMENT ON COLUMN ${schema~}.notification.level
    IS 'alert | warning | caution | information';

    插入 json 的值

    '{"600104": ["abc@qq.com", ""],"600101": ["abc@qq.com", ""]}'

    添加 删除一列

    ALTER TABLE edsi.plan
    ADD COLUMN location character varying(100);

    ALTER TABLE edsi.child
    DROP COLUMN location;

    相关文章

      网友评论

          本文标题:postgreSQL 常用sql

          本文链接:https://www.haomeiwen.com/subject/brvmuhtx.html