PostgreSQL資料庫中獲取表主鍵名稱

2021-09-08 17:35:05 字數 767 閱讀 9051

一、如下表示,要獲取teacher表的主鍵資訊:

select pg_constraint.conname as pk_name,pg_attribute.attname as colname,pg_type.typname as typename from

pg_constraint

inner

join

pg_class

on pg_constraint.conrelid =

pg_class.oid

inner

join pg_attribute on pg_attribute.attrelid =

pg_class.oid

and pg_attribute.attnum = pg_constraint.conkey[1]

inner

join pg_type on pg_type.oid =

pg_attribute.atttypid

where pg_class.relname =

'teacher

'and pg_constraint.contype='p

'

二、效果圖:

由圖可知,主鍵約束的名稱為pk_teacher,主鍵字段(列)為"id",主鍵欄位的型別為:uuid。

——宋興柱發表於2023年7月30日 濟南中迪智業。    

spark 中 postgresql資料庫使用

畢竟是號稱世界上最先進的資料庫,還是要會一點的 一 最近是在spark裡面使用,需要從資料庫中直接讀出資料構建dataframe,但是這裡有乙個坑點,我需要拿到每天的資料,但是如果不使用spark.sql 執行sql語句,而是使用其他api,就涉及乙個日期條件怎麼寫的問題,最後解決時是使用spark...

postgresql模板資料庫

template0和template1為postgresql資料庫的模板資料庫,新建的資料庫預設使用template1作為模板。template0和template1的區別在於template0無法修改,因此你可以修改template1資料庫以定製新建立的資料庫。template資料庫無法被刪除 d...

postgresql資料庫安裝

安裝並初始化 1 解壓資料庫並放到指定目錄 在opt目錄下 tar xvzf postgresql 10.1 1 linux x64 binaries.tar.gz 解壓出來之後目錄為pgsql 2 mv pgsql usr local pgsql 3 建立pgsql使用者並設定密碼 useradd...