Comments (2)
I think the path to take is:
col_identity_is(:schema, :table, :column, :type [, :desc]);
col_identity_options_are(:schema, :table, :column, ARRAY[ :options ] [, :desc])
col_identity_expression_is(:schema, :table, :column, :expression [, :desc])
At present, I think I'll split the work into 2 parts. Part 1 is the first function as that's the most bang for the buck in many ways. Part 2 will be the last 2 functions since they won't be used as much.
BTW, schema is required as we need that to get the OID of the column we're working on, so I don't think we can have a "schema-less" version of these functions.
If you look at the docs for "CREATE TABLE", this is documented as a column constraint (attribute) and as:
GENERATED ALWAYS AS ( generation_expr ) STORED
-- or --
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
-- The generation expression can refer to other columns in the table, but not other generated columns. Any functions and operators used must be immutable. References to other tables are not allowed.
-- For sequence_options see doc for CREATE SEQUENCE
-- It creates an implicit sequence, which means that it can only occur on SMALLINT, INT, or BIGINT type columns.
The first function would be something in the direction of:
CREATE OR REPLACE FUNCTION col_identity_is(
p_schema VARCHAR,
p_table VARCHAR,
p_column VARCHAR,
p_type VARCHAR, -- 'always','default','stored'
p_desc VARCHAR -- could allow to be optional
)
RETURNS BOOLEAN AS $$
DECLARE
v_type: CHAR;
v_expr: VARCHAR;
BEGIN
/*
-- might need to change the function to return the expression too even if we don't use it here
SELECT _get_column_identity(p_schema, p_table, p_column) INTO v_type, v_expr;
if v_type is null, then throw an exception about col not having identity
case statement to convert lower(p_type) to a char for comparison
if v_type != p_type, then throw an exception about not matching type
return true;
*/
END;
$$ LANGUAGE PLPGSQL;
I need to rework the psuedo-code for the generated_expression and sequence_options since I had them combined into one; I'll add that later.
Notes:
- Probably need to remove all spaces in the generated_expression before comparing to make that easier to match.
- For the sequence_options, that probably should be an array, then we'd need to compare that to the array in the catalog table somehow. (Does pgTap already do this since it already knows about sequences? Check to see.)
from pgtap.
From the email thread, David suggests col_identity_type_is()
. That's works for me.
from pgtap.
Related Issues (20)
- table_privs_are is falsely reporting extra privileges HOT 4
- Question: pgTap on Greenplum? HOT 3
- How to use the return value of an insert? HOT 7
- [pg_prove] "tests out of sequence" failure with multiple checks in a single statement HOT 1
- Is Postgres 15 supported? HOT 1
- Regression test ruletap.sql failed due to recent change in PG16
- Unable to install on MacOS HOT 2
- New release with PG16 support HOT 10
- `col_type_is` cannot handle expected type `interval second(0)` HOT 24
- add has_comment()
- Allow to test with snapshots HOT 2
- How to install and use pgtap in different schema? HOT 1
- passing the name of a test directory to pg_prove return 'Result: NOTESTS' HOT 1
- Cannot install pgTAP 1.3.1 HOT 4
- No longer installable by non-superuser HOT 9
- Function to check procedure privileges HOT 3
- Bad links in documentation HOT 1
- Feature: index_is_partial(), index_partial_clause_is()
- Feature: has_trigger_events() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pgtap.